<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2021/8/6
 * Time: 15:37
 */

namespace app\admin\controller;


use think\Db;

class Realname extends Base
{
    public function index(){
        if(request()->isAjax ()){
            $user_phone = trim(input('user_phone'));
        
            $where['user_is_real_name'] = 2;
            if(isset($user_phone) && $user_phone != ''){
                $where['user_phone'] = ['like', '%' . $user_phone . '%'];
            }
        
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::name('u_user')->where($where)->count();// 获取总条数
            $lists = Db::name('u_user')
                ->field('user_id, user_phone, user_card_code, user_real_name, user_status, user_time')
                ->where($where)
                ->page($Nowpage,$limits)
                ->order('user_real_name_time desc')
                ->select();
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        return $this->fetch();
    }
    
    /**
     * 审核通过
     * @return \think\response\Json
     */
    public function userAllow(){
        $user_id = input('id');
        $res = Db::table('up_u_user')->where('user_id', $user_id)->setField('user_is_real_name', 3);
        if($res){
            return json(['code' => 200, 'msg' => '操作成功']);
        }else{
            return json(['code' => 100, 'msg' => '操作失败']);
        }
    }
    
    /**
     * 审核拒绝
     * @return \think\response\Json
     */
    public function userRefuse(){
        $user_id = input('id');
        $res = Db::table('up_u_user')->where('user_id', $user_id)->setField('user_is_real_name', 4);
        if($res){
            return json(['code' => 200, 'msg' => '操作成功']);
        }else{
            return json(['code' => 100, 'msg' => '操作失败']);
        }
    }
}